﻿using System;

namespace Models
{
    /// <summary>
    /// The results of a query
    /// </summary>
    public class QueryResult : ModelBase
    {
        /// <summary>
        /// Create a result set for a query
        /// </summary>
        /// <param name="result">The results</param>
        /// <param name="querySucceeded">Whether or not the query succeeded</param>
        /// <param name="errorMessage">Contains an error message if the query failed</param>
        /// <param name="databaseId">The ID of the database to link this query result set to</param>
        public QueryResult(object result, bool querySucceeded, string errorMessage, Guid databaseId)
        {
            Result = result;
            QuerySucceeded = querySucceeded;
            ErrorMessage = errorMessage;
            DatabaseId = databaseId;
        }

        /// <summary>
        /// Create a query result set for a successful query
        /// </summary>
        /// <param name="result">The results</param>
        /// <param name="databaseId">The ID of the database to link this query result set to</param>
        public QueryResult(object result, Guid databaseId)
            : this(result, true, string.Empty, databaseId)
        {
        }

        /// <summary>
        /// Create a query result set for a failed query
        /// </summary>
        /// <param name="result">The results</param>
        /// <param name="errorMessage">Contains an error message if the query failed</param>
        /// <param name="databaseId">The ID of the database to link this query result set to</param>
        public QueryResult(object result, string errorMessage, Guid databaseId)
            : this(result, false, errorMessage, databaseId)
        {
        }

        /// <summary>
        /// The result of a query
        /// </summary>
        public object Result
        {
            get
            {
                return m_Result;
            }
            set
            {
                m_Result = value;
                OnPropertyChanged("Result");
            }
        }

        /// <summary>
        /// Whether or not the query succeeded
        /// </summary>
        public bool QuerySucceeded
        {
            get
            {
                return m_QuerySucceeded;
            }
            set
            {
                m_QuerySucceeded = value;
                OnPropertyChanged("QuerySucceeded");
            }
        }

        /// <summary>
        /// Contains an error message if the query failed
        /// </summary>
        public string ErrorMessage
        {
            get
            {
                return m_ErrorMessage;
            }
            set
            {
                m_ErrorMessage = value;
                OnPropertyChanged("ErrorMessage");
            }
        }

        /// <summary>
        /// The ID of the database that this query result set is linked to
        /// </summary>
        public Guid DatabaseId
        {
            get
            {
                return m_DatabaseId;
            }
            set
            {
                m_DatabaseId = value;
                OnPropertyChanged("DatabaseId");
            }
        }

        /// <summary>
        /// Whether or not this result set has been selected for export
        /// </summary>
        public bool SelectedForExport
        {
            get
            {
                return m_SelectedForExport;
            }
            set
            {
                m_SelectedForExport = value;
                OnPropertyChanged("SelectedForExport");
            }
        }

        private Guid m_DatabaseId;
        private string m_ErrorMessage;
        private bool m_QuerySucceeded;
        private object m_Result;
        private bool m_SelectedForExport;
    }
}
